﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using tracker.Models.DTO;
using System.Data;

namespace tracker.Models.DAL
{
    public class TrackLogDAL:ErpCatalogueBaseBL
    {
        #region Properties Define
        private string FIELD_DEVICEKEY = "DeviceKey";
        
        #endregion

        #region STORE NAME
        public const string TRACKLOG_GETLAST = "TrackLog_GetLast";
        public const string TRACKLOG_GETLASTALARM = "TrackLog_GetLastAlarm";
        #endregion
    

        public  ETrackLog getLastByDeviceKey(string deviceKey)
        {
            ETrackLog trackLog = null;
            DataSet ds = ErpCatalogueBaseBL.SelectAllWithParameter(TRACKLOG_GETLAST,
                                                                 new string[] { FIELD_DEVICEKEY },
                                                                 new object[] { deviceKey });
            

            if (Utilities.hasRow(ds))
            {
                DataTable dt = ds.Tables[0];
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    trackLog = new ETrackLog();
                    trackLog = ETrackLog.create(dt.Rows[i]);
                }
            }
            return trackLog;
        }
        public ETrackLog getLastAlarmByDeviceKey(string deviceKey)
        {
            ETrackLog trackLog = null;
            DataSet ds = ErpCatalogueBaseBL.SelectAllWithParameter(TRACKLOG_GETLASTALARM,
                                                                 new string[] { FIELD_DEVICEKEY },
                                                                 new object[] { deviceKey });

            if (Utilities.hasRow(ds))
            {
                DataTable dt = ds.Tables[0];
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    trackLog = new ETrackLog();
                    trackLog = ETrackLog.create(dt.Rows[i]);
                }
            }
            return trackLog;
        }
    }
}